sap.ui.define([
    'jquery.sap.global', 'sap/ui/core/mvc/Controller', 'sap/ui/model/json/JSONModel','sap/lx/nba/user/Constants'
], function(jQuery, Controller, JSONModel, Formatter , Constants) {

    "use strict";

    var creationCtrl = Controller.extend("sap.lx.nba.user.show", {

        onInit: function(event) {

/*          var model = new JSONModel({
                
                    list:[{
                        icon:"http://mat1.gtimg.com/sports/nba/logo/1602/25.png",
                        name:"thunder",
                        location:"china",
                        birth:"today",
                        champion:"two",
                        coach:"lx"
                    }]
                        
                    }
            
            ) ;
            */

/*            var model = new JSONModel();

            model.loadData("../get/team");

            this.getView().setModel(model, "team");
            this.model_apps = model;*/
            
            Constants.email ;

            this.page = this.getView().byId("page");
            this.topTable = this.getView().byId("topTable");
            this.belowTable = this.getView().byId("belowTable");

        },
        getRouter: function() {
            return sap.ui.core.UIComponent.getRouterFor(this);
        },
        onNavButtonPress: function() {

            history.go(-1);

        },
        onSave: function() {
            
            this.page.setBusy(true) ;

            var data = this.topTable.getModifiedData();

            var add = data.add;

            var less = data.less;

            var update = data.update;

            var model = new JSONModel();

            for (var i = 0; i < add.length; i++) {
                model.setData(add[i]);
                var body = model.getJSON();
                $.ajax({
                    url: "../user/top/add",
                    contentType: "application/json",
                    data: body,
                    cache: false,
                    async: false,
                    type: "POST",
                    dataType: 'json/xml/html',
                    success: function(result) {

                    }
                });
            }
            for (var i = 0; i < less.length; i++) {
                model.setData(less[i]);
                var body = model.getJSON();
                $.ajax({
                    url: "../user/top/delete",
                    contentType: "application/json",
                    data: body,
                    cache: false,
                    async: false,
                    type: "POST",
                    dataType: 'json/xml/html',
                    success: function(result) {

                    }
                });
            }
            for (var i = 0; i < update.length; i++) {
                model.setData(update[i]);
                var body = model.getJSON();
                $.ajax({
                    url: "../user/top/update",
                    contentType: "application/json",
                    data: body,
                    cache: false,
                    async: false,
                    type: "POST",
                    dataType: 'json/xml/html',
                    success: function(result) {

                    }
                });
            }

            this.topTable.refresh();
            this.belowTable.refresh();

            this.topTable.toDisplay();
            this.belowTable.toDisplay();
            
            this.page.setBusy(false) ;
            
        },
        onEdit: function() {
            this.topTable.toEdit();
            this.belowTable.toEdit();
        },

    });

    return creationCtrl;

});
